/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package aic.beans;

import java.util.LinkedList;
import java.util.List;
import java.util.UUID;
import javax.xml.bind.annotation.XmlAttribute;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlID;
import javax.xml.bind.annotation.XmlRootElement;

@XmlRootElement
public class Customer {

//    private static int cntID = 0;
    private String id;
    private String name;
    private Address address;
    private Payment_Preference payment_preference;
    private List<Order> orders = new LinkedList<Order>();

    public Customer() {
//        cntID++;
//        this.id = "Customer" + cntID;
        UUID uuid = UUID.randomUUID();
        this.id = uuid.toString();
    }

    /**
     * New constructor
     * !!!ATTENTION!!!
     * You may create several Customer objects with the same id!
     *
     * @param id
     * @param name
     * @param address
     * @param payment_preference
     */
    public Customer(String id, String name, Address address, Payment_Preference payment_preference) {
        this.id = id;
        this.name = name;
        this.address = address;
        this.payment_preference = payment_preference;
    }

    @XmlAttribute
    @XmlID
    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }

    @XmlElement
    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    @XmlElement
    public Address getAddress() {
        return address;
    }

    public void setAddress(Address address) {
        this.address = address;
    }

    @XmlElement
    public Payment_Preference getPayment_preference() {
        return payment_preference;
    }

    public void setPayment_preference(Payment_Preference payment_preference) {
        this.payment_preference = payment_preference;
    }

    @XmlElement(name = "order")
    public List<Order> getOrders() {
        return orders;
    }

    public void setOrders(List<Order> orders) {
        this.orders = orders;
    }

    @Override
    public String toString() {
        return "id: " + this.id + " / name: " + this.name;
    }

    @Override
    public boolean equals(Object obj) {
        if (this == obj) {
            return true;
        }
        if (obj == null) {
            return false;
        }
        if (this.getClass() != obj.getClass()) {
            return false;
        }
        final Customer other = (Customer) obj;
        if (!this.getName().equals(other.getName())) {
            return false;
        }
        if (!this.getId().equals(other.getId())) {
            return false;
        }

        return true;
    }

    @Override
    public int hashCode() {
        int hash = 7;
        hash = 89 * hash + (this.id != null ? this.id.hashCode() : 0);
        hash = 89 * hash + (this.name != null ? this.name.hashCode() : 0);
        hash = 89 * hash + (this.address != null ? this.address.hashCode() : 0);
        return hash;
    }
}
